<template>
  <a-modal
      v-bind="options"
      @ok="handleOk"
      @cancel="handleCancel">
    <div class="modal-content-wrap">
      {{options.contentTips}}
    </div>
  </a-modal>
</template>

<script>
export default {
  props: {
    customOpt: Object
  },
  data() {
    return {
      options: {
        title: '我是标题',
        width: 300,
        visible: false,
        loading: false,
        centered: true,
        contentTips: '我是内容'
      },
      sourceOptions: { // 事件的点击来源.主要用于指向用户点击ok后的去处
        source: '', // 去处
        params: {} // 参数
      }
    }
  },
  watch: {
    customOpt: {
      handler(nVal) {
        if (nVal) {
          Object.assign(this.options, { ...this.customOpt })
        }
      },
      immediate: true,
      deep: true
    }
  },
  methods: {
    handleOk() {
      this.handlerVisible(false, this.sourceOptions)
      this.$emit('ok')
    },
    handleCancel() {
      this.handlerVisible(false)
      this.$emit('cancel')
    },
    // 是否展示加载中的动画
    showLoading(v) {
      this.options.loading = v
    },
    // 处理弹窗是否显示
    handlerVisible(v, sourceOptions) {
      this.sourceOptions = sourceOptions
      this.options.visible = v
    }
  }
}
</script>
